﻿using IDLETD.Agent;
using IDLETD.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace IDLETD.FSM
{
    public class StateMove : StateBase
    {


        public override StateEnum State => StateEnum.移动;

        private BaseGameObject onwer = null;

        private SportAgent sportAngent;
        public override SportAgent SportAgent
        {
            get { return sportAngent; }
            set { sportAngent = value; }
        }

        private CrashAgent crashAngent;
        public override CrashAgent CrashAgent
        {
            get { return crashAngent; }
            set { crashAngent = value; }
        }


        public override BaseGameObject Onwer
        {
            get { return onwer; }
            set { onwer = value; }
        }

        public override void Enter(object[] objs)
        {
            try
            {
                if (objs.Count() != 1) return;
                SportAgent.Path = (List<Point>)objs[0];
                if (SportAgent.Path == null) return;
                onwer.X = SportAgent.Path[0].X - onwer.Width / 2; 
                onwer.Y = SportAgent.Path[0].Y - onwer.Height / 2;
                SportAgent.TargetPoint = SportAgent.Path[1];
            }
            catch
            {

            }
        }

        public override void Excute()
        {
            if (SportAgent.Move())
                onwer.GoDead();
        }

        public override void Leave()
        {
            SportAgent.Path = null;
        }
    }
}
